def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def max_prime_from_digits(number):
    number_str = str(number)
    if len(number_str) != 4 or not number_str.isdigit():
        return 0
    
    max_prime = 0
    for start in range(len(number_str)):
        for end in range(start + 1, len(number_str) + 1):
            num = int(number_str[start:end])
            if is_prime(num) and num > max_prime:
                max_prime = num
    
    return max_prime

number = int(input())
print(max_prime_from_digits(number))
